package com.wm.task.view;

import com.wm.task.dao.UserDAO;
import com.wm.task.vo.Movie;
import com.wm.task.vo.ScoreRecord;
import com.wm.task.vo.User;

import java.util.ArrayList;
import java.util.List;

public class UserView extends BaseView {
    private User user = new User();
    private UserDAO userDAO = new UserDAO();
    private List<Movie> movieList;
    private ScoreRecord scoreRecord = new ScoreRecord();
    private List<ScoreRecord> scoreRecords = new ArrayList<>();

    public UserView() {
    }

    public UserView(User user) {
        this.user = user;
    }

    @Override
    protected void handleChoice(String choice) {
        switch (choice) {
            case "1":
                movieList();//电影列表
                break;
            case "2":
                scoreRecord();//我的评分记录
                break;
            case "3":
                ranking();//电影排行
                break;
            case "4":
                amend();//个人信息修改
                break;
        }
    }

    private void movieList() {
        System.out.println("===电影列表===");
        movieList = userDAO.movieList();
        for (Movie movie : movieList) {
            System.out.println(movie.getId() + "电影:" + movie.getTitle() + "\n上映时间:" + movie.getReleaseYear());
        }
        System.out.println("是否打分:y/n");
        if ("n".equals(sc.next())) {
            return;
        }
        System.out.println("请选择电影进行评分:");
        int id = sc.nextInt();
        System.out.println(movieList.get(id - 1).getId() + "   片名/原片名:" + movieList.get(id - 1).getTitle() + "/" + movieList.get(id - 1).getOriginalTitle() + "\n"
                + "年份:" + movieList.get(id - 1).getReleaseYear() + "   时长:" + movieList.get(id - 1).getDuration() + "   语言:" + movieList.get(id - 1).getLanguage() + "   国家:" + movieList.get(id - 1).getCountry() + "\n"
                + "评分:" + movieList.get(id - 1).getRating() + "   评分人数:" + movieList.get(id - 1).getRatingCount() + "\n"
                + "概要:" + movieList.get(id - 1).getPlotSummary() + "\n"
                + "类型:" + movieList.get(id - 1).getType());
        System.out.println("请打分(0~10):");
        float rating = sc.nextFloat();
        scoreRecord = userDAO.score(user, movieList.get(id - 1), rating);
        if (scoreRecord == null) {
            System.out.println("评分成功");
        } else {
            System.out.println("您已打分");
            System.out.println(scoreRecord.getMovie() + "\n分数:" + scoreRecord.getScore() + "\n时间:" + scoreRecord.getTime());
        }


    }

    private void scoreRecord() {
        System.out.println("===评分记录===");
        scoreRecords = userDAO.scoreRecord();
        for (ScoreRecord record : scoreRecords) {
            System.out.println(record.getMovie() + "   分数:" + record.getScore() + "   时间:" + record.getTime());
        }

    }

    private void ranking() {

    }

    private void amend() {

    }

    @Override
    protected String getTitle() {
        return "万码影评网(用户:张三)";
    }

    @Override
    protected String[] getMenus() {
        return new String[]{"电影列表", "我的评分记录", "电影排行", "个人信息修改", "退出"};
    }
}
